package com.xinzhi.controller;

import com.xinzhi.service.IInsertService;
import com.xinzhi.service.impl.InsertServiceImpl;
import com.xinzhi.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 *
 */
@RestController
public class InsertController {


    @Autowired
    private InsertServiceImpl insertService;

    /**
     * 通过手机号注册
     * @param phone 手机号
     * @return 返回值信息
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody Map<String, String> payload){
        String phone = payload.get("phone");
        return insertService.addPhone(phone);
    }

    /**
     * 通过手机号发送验证码
     * @param phone 手机号
     * @return 返回值信息
     */
    @PostMapping("/sendCode")
    public Result sendCode(@RequestBody Map<String, String> payload) {
        String phone = payload.get("phone");
        return insertService.sendVerificationCode(phone);
    }

    /**
     * 接受并判断验证码
     * @param phone 手机号
     * @param code 验证码
     * @return 返回值信息
     */
    @PostMapping("/verifyCode")
    public Result verifyCode(@RequestBody Map<String, String> payload) {
        String phone = payload.get("phone");
        String code = payload.get("code");
        return insertService.verifyCode(phone, code);
    }

    /**
     *   通过手机号查询银行卡信息
     * @param phone  手机号
     * @return 返回值信息
     */
    @GetMapping("/selectBankCard")
    public List selectBankCard(String phone) {
       return insertService.queryBankCard(phone);

    }

    /**
     *   通过手机号注销
     *   @param phone  手机号
     *   @return 返回值信息
     *
     */

    @PostMapping("/deleteUser")

    public Result deleteUser(String phone) {

        return insertService.deleteUser(phone);
    }



}
